/* eslint-disable */
const Http404 = {}
const Http401 = {}

/**
 * @property   {Object}   content 上下文信息 包含req, res 
 * @property   {number}   status  状态码
 * */
class Response {
    constructor(content, status) {
        this.name = 'response'
        this.content = content
        this.status = status
    }
}

class TemplateResponse {
    constructor(template, context) {
        this.name = 'template'
        this.template = template
        this.context = context
    }
}

class JsonResponse {
    constructor(data, type = 'json') {
        this.name = 'json'
        this.data = data
        this.type = type
    }
}

class RedirectResponse {
    constructor(location) {
        this.name = 'redirect'
        this.location = location
    }
}

const HttpResponse = (content, status = 200) => {
    return new Response(content, status)
}

/**
 * @param      {string}          template    静态文件 路径
 * @param       {object}          context    上下文信息
 * */
function render(template, context) {
    return new TemplateResponse(template, context)
}

/**
 * @param      {string}          location    重定向路径
 * */
function redirect(location) {
    return new RedirectResponse(location)
}

/**
 * @param      {Object}          data    数据
 * @param      {string}          type    类型
 * */
function json(data, type = 'json') {
    return new JsonResponse(data, type)
}

module.exports = {
    Response,
    JsonResponse,
    TemplateResponse,
    Http404,
    Http401,
    RedirectResponse,
    HttpResponse,
    redirect,
    render,
    json
}